//
//  LXUMSocialManager.m
//  LXUMSocialManager
//
//  Created by zijie on 2019/1/14.
//  Copyright © 2019 ehomepay. All rights reserved.
//

#import "LXUMSocialManager.h"
#import <UMSocialCore/UMSocialCore.h>
#import "WxApi.h"

@interface LXUMSocialManager ()

@property (nonatomic, strong) dispatch_queue_t queue;

@end

@implementation LXUMSocialManager

+ (instancetype)sharedWithUmSocialAppkey:(NSString *)appkey {
    return [[self alloc] initWithUmSocialAppkey:appkey];
}

- (instancetype)initWithUmSocialAppkey:(NSString *)appkey {
    if (self = [super init]) {
        _queue = dispatch_queue_create("com.ehomepay.umsocial", DISPATCH_QUEUE_SERIAL);
        [self setUMSocialAppkey:appkey];
    }
    return self;
}

// 设置友盟appkey
- (void)setUMSocialAppkey:(NSString *)appkey {
    dispatch_async(_queue, ^{
        [[UMSocialManager defaultManager] setUmSocialAppkey:appkey];
    });
}

// 设置新浪的appKey、appSecret
- (void)setSinaAppkey:(NSString *)appkey appSecret:(NSString *)appSecret redirectURL:(NSString *)redirectURL {
    dispatch_async(_queue, ^{
        [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:appkey appSecret:appSecret redirectURL:redirectURL];
    });
}

// 设置分享到QQ互联的appID
- (void)setQQAppkey:(NSString *)appkey appSecret:(NSString *)appSecret redirectURL:(NSString *)redirectURL {
    dispatch_async(_queue, ^{
        [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:appkey appSecret:appSecret redirectURL:redirectURL];
    });
}

// 设置微信的appKey、appSecret
- (void)setWXAppkey:(NSString *)appkey appSecret:(NSString *)appSecret redirectURL:(NSString *)redirectURL {
    dispatch_async(_queue, ^{
        [WXApi registerApp:appkey];
        [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:appkey appSecret:appSecret redirectURL:redirectURL];
    });
}

@end
